<%--
  Created by IntelliJ IDEA.
  User: Boss
  Date: 2021/5/10
  Time: 8:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<style type="text/css">
    #hidd{
        text-align: center; /*可以让盒子内容（文字 行内元素 行内块元素）居中对齐*/
        width: 300px;
        height: 100px;
        margin: 100px auto;
        display: none;
    }
    #BeOver{
        text-align: center; /*可以让盒子内容（文字 行内元素 行内块元素）居中对齐*/
        width: 300px;
        height: 100px;
        margin: 100px auto;
        display: none;
    }
</style>
<body>
<%
    String path=request.getContextPath();
    String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<div>
    <form method="post" action="<%=basePath%>BorrowServlet?opr=insertSelect">
        <table border="1">
            <tr>
                <th colspan="2" style="font-size: 20px">还书管理</th>
            </tr>
            <tr>
                <td>读者卡号：</td>
                <td><input name="id" type="text"></td>
            </tr>
            <tr>
                <td>书籍编号：</td>
                <td><input name="bookId" type="text"></td>
            </tr>
            <tr>
                <td>归还时间：</td>
                <td><input name="endTime" type="text"></td>
            </tr>
        </table>
        <br>
        <input name="huan" type="button" value="还书">
    </form>
</div>
<div id="BeOver">
    <form action="#" method="post">
        <table border="1">
            <tr>
                <th colspan="2">用户违约</th>
            </tr>
            <tr>
                <th>读者卡号：</th>
                <td><input type="text" name="cardId" class="card"></td>
            </tr>
            <tr>
                <th>书籍编号：</th>
                <td><input type="text" name="bookId" class="book"></td>
            </tr>
            <tr>
                <th>借书时间：</th>
                <td><input type="text" name="startTime" class="start"></td>
            </tr>
            <tr>
                <th>借阅天数：</th>
                <td><input type="text" name="day" class="day"></td>
            </tr>
            <tr>
                <th>还书时间：</th>
                <td><input type="text" name="endTime" class="end"></td>
            </tr>
            <tr>
                <th>违约类型：</th>
                <td><input type="text" name="type" class="typ"></td>
            </tr>
            <tr>
                <th>违约金额：</th>
                <td><input type="text" name="money" class="money"></td>
            </tr>
            <tr>
                <td colspan="2"><input name="Tian" type="button" value="添加" class="Tian" style="margin-left: 50px">&nbsp;&nbsp;&nbsp;&nbsp;<input name="QuNo" type="button" class="QuNo" value="取消" style="margin-left: 50px"></td>
            </tr>
        </table>
    </form>
</div>
<div id="hidd">
    <form action="#" method="post">
        <table border="1">
            <tr>
                <th style="background-color: aquamarine">提示！</th>
            </tr>
            <tr>
                <td class="huan" style="text-align: center;width: 300px;height: 100px;"></td>
            </tr>
            <tr>
                <td style="padding-left: 125px;"><input name="que" type="button" value="确认" style="width: 50px"></td>
            </tr>
        </table>
    </form>
</div>
<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("input[name='huan']").click(function () {
            let nameid=$("input[name='id']").val();
            let nameBookId=$("input[name='bookId']").val();
            let nameEndTime=$("input[name='endTime']").val();
            $.ajax({
                url:"BorrowServlet?opr=insertSelect",
                type:"post",
                data:{
                    id:nameid,
                    bookId:nameBookId,
                    endTime:nameEndTime
                },
                dataType:"json",
                success:function (date) {
                    if (date){
                        $("#hidd").show();
                        $(".huan").text("还书成功！")
                        $.ajax({
                            url: "BorrowServlet?opr=day",
                            type: "post",
                            data: {
                                id:nameid,
                                bookId: nameBookId
                            },
                            dataType: "json",
                            success:function (date) {
                                if (date){
                                    $("#hidd").show();
                                    $(".huan").text("该用户已逾期！")
                                    $("input[name='que']").click(function () {
                                        $("#BeOver").show();
                                        $("#hidd").hide();
                                        let cardId=$(".card").val(nameid);
                                        let BookId=$(".book").val(nameBookId);
                                        let star=$(".start").val();
                                        let day=$(".day").val(<%=session.getAttribute("day2")%>);
                                        let nameEndTime=$("input[name='endTime']").val();
                                        let EndTime=$(".end").val(nameEndTime);
                                        let tp=$(".typ").val();
                                        let money=$(".money").val();
                                        $.ajax({
                                            url:"BorrowServlet?opr=findInsert",
                                            type:"post",
                                            data:{
                                                cardId:cardId,
                                                bookId:BookId,
                                                startTime:star,
                                                day:day,
                                                endTime: EndTime,
                                                type:tp,
                                                money: money
                                            },
                                            dataType:"json",
                                            success:function (date) {
                                                if (date){
                                                    alert("添加成功！")
                                                }
                                            }
                                        })
                                    })
                                }
                            }
                        })
                    }else {
                        $("#hidd").show();
                        $(".huan").text("还书失败！该用户未借书或书籍编号错误！")
                    }
                },error:function () {
                    alert("失败")
                }
            })
        })
        $(".QuNo").click(function () {
            $("#BeOver").hide()
        })
    })
</script>
</body>
</html>
